import { resolve } from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ts from 'rollup-plugin-typescript2'

// https://cn.vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],

  publicDir: false,

  resolve: {
    alias: [{ find: '@', replacement: resolve(__dirname, 'src') }]
  },

  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.ts'),
      name: 'vue-router-tab'
    },
    sourcemap: true,
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ['vue'],
      output: {
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: {
          vue: 'Vue'
        }
      },
      plugins: [
        ts({
          tsconfig: resolve(__dirname, 'tsconfig.json'),
          cacheRoot: resolve(__dirname, 'node_modules/.rts2_cache'),
          tsconfigOverride: {
            compilerOptions: {
              sourceMap: true,
              declaration: true,
              declarationMap: true
            }
          }
        })
      ]
    }
  },

  css: {
    preprocessorOptions: {
      scss: {
        // scss 附加全局变量
        additionalData: `
          @use "sass:math";
          @import "@/assets/css/var.scss";
        `
      }
    }
  }
})
